package presenter;


import java.util.Observer;

import bean.GoodsModel;
import interfaces.IShopMallSearch;
import responsitory.ShopMallSearch;
import util.volley.ICompleteListener;
import util.volley.ResultEntity;

/**
 * 商品
 */
public class ShopMallSearchPresenter extends BasePresenter implements IShopMallSearch<GoodsModel> {
    //商品列表
    public static final String Serach_success = ShopMallSearchPresenter.class.getName()
            + "_Serach_success";
    public static final String Serach_fail = ShopMallSearchPresenter.class.getName()
            + "_Serach_fail";
    //商品搜索
    public static final String mall_sousuo_success = ShopMallSearchPresenter.class.getName()
            + "_mall_sousuo_success";
    public static final String mall_sousuo_fail = ShopMallSearchPresenter.class.getName()
            + "_mall_sousuo_fail";
    //支付方式
    public static final String pay_fangshi_success = ShopMallSearchPresenter.class.getName()
            + "_pay_fangshi_success";
    public static final String pay_fangshi_fail = ShopMallSearchPresenter.class.getName()
            + "_pay_fangshi_fail";
    //商品详情
    public static final String mall_xq_success = ShopMallSearchPresenter.class.getName()
            + "_mall_xq_success";
    public static final String mall_xq_fail = ShopMallSearchPresenter.class.getName()
            + "_mall_xq_fail";

    //子类目查询
    public static final String leimu_success = ShopMallSearchPresenter.class.getName()
            + "_leimu_success";
    public static final String leimu_fail = ShopMallSearchPresenter.class.getName()
            + "_leimu_fail";


    public ShopMallSearchPresenter(Observer observer) {
        super(observer);
    }

    @Override
    public void shangPinList(String page_index, String page_size, String cate_id, String prop_id, String order, String keyword, String l_price, String r_price) {
        IShopMallSearch shopsearch = new ShopMallSearch(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(Serach_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(Serach_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.shangPinList(page_index,page_size,cate_id,prop_id,order,keyword,l_price,r_price);
    }

    @Override
    public void getMallSouSuo(String keyword) {
        IShopMallSearch shopsearch = new ShopMallSearch(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(mall_sousuo_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(mall_sousuo_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.getMallSouSuo(keyword);
    }

    @Override
    public void payFangShi() {
        IShopMallSearch shopsearch = new ShopMallSearch(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(pay_fangshi_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(pay_fangshi_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.payFangShi();
    }
    @Override
    public void mallXiangQing(String id) {
        IShopMallSearch shopsearch = new ShopMallSearch(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(mall_xq_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(mall_xq_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.mallXiangQing(id);
    }

    @Override
    public void LeiMuQuery(String cate_id) {
        IShopMallSearch shopsearch = new ShopMallSearch(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(leimu_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(leimu_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.LeiMuQuery(cate_id);
    }

}
